home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / submit / submit_mgt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  7.3 KB  |  337 lines

  1. /* submit_mgt.c: management stuff */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/submit/RCS/submit_mgt.c,v 6.0 1991/12/18 20:28:02 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/submit/RCS/submit_mgt.c,v 6.0 1991/12/18 20:28:02 jpo Rel $
  9.  *
  10.  * $Log: submit_mgt.c,v $
  11.  * Revision 6.0  1991/12/18  20:28:02  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "head.h"
  19. #include "prm.h"
  20. #include "q.h"
  21. #include "dr.h"
  22. #include "ap.h"
  23. #include <sys/time.h>
  24.  
  25. /* -- externals -- */
  26. extern int max_hops, max_loops;
  27. extern  time_t          time();
  28. extern  int             privileged;
  29. extern    int        return_interval_norm,
  30.             return_interval_low,
  31.             return_interval_high,
  32.             warn_interval;
  33. extern  int             accept_all;
  34. extern    int        notrace;
  35. extern  char            *loc_dom_site, *loc_dom_mta,
  36.             *ia5_bp, *hdr_822_bp,
  37.             io_fpart[];
  38.  
  39. /* -- globals -- */
  40. CHAN                    *ch_inbound;
  41. char                    *mgt_inhost;
  42. int                     mgt_adtype = AD_822_TYPE;
  43. extern void        message_failure();
  44. extern void        rd_rfchdr ();
  45. extern void        pro_reply ();
  46. extern void        err_abrt ();
  47.  
  48.  
  49. /* -- local routines -- */
  50. int            cntrl_mgt();
  51. int            q_mgt();
  52. void            message_failure();
  53. void            msg_mgt();
  54. void            time_mgt();
  55. void            txt_mgt();
  56.  
  57. static void        tracecheck_mgt();
  58.  
  59.  
  60.  
  61.  
  62. /* ---------------------  Begin  Routines  -------------------------------- */
  63.  
  64.  
  65.  
  66.  
  67. int cntrl_mgt (prm, qp)
  68. register struct prm_vars        *prm;
  69. register Q_struct               *qp;
  70. {
  71.     CHAN    *ch_in;
  72.  
  73.     PP_TRACE (("submit/cntrl_mgt (type = %d)", mgt_adtype));
  74.  
  75.     accept_all = (prm -> prm_opts & PRM_ACCEPTALL) == PRM_ACCEPTALL;
  76.     notrace = (prm -> prm_opts & PRM_NOTRACE) == PRM_NOTRACE;
  77.  
  78.     /* -- what incomming channel is calling submit -- */
  79.  
  80.     if (qp -> inbound == NULL ||
  81.         (ch_inbound = ch_in = qp -> inbound -> li_chan) == NULLCHAN)
  82.         err_abrt (RP_MECH, "No channel given");
  83.  
  84.     if (ch_in -> ch_access == CH_MTA) {
  85.         if (!privileged)
  86.             err_abrt (RP_USER, "Privileged channel");
  87.     }
  88.     if (ch_in -> ch_chan_type != CH_BOTH &&
  89.         ch_in -> ch_chan_type != CH_IN &&
  90.         ch_in -> ch_chan_type != CH_WARNING) 
  91.         err_abrt (RP_MECH, "Channel %s not inbound",
  92.               ch_in -> ch_name);
  93.  
  94.     if (ch_in -> ch_in_ad_subtype == AD_JNT
  95.         || ch_in -> ch_in_ad_subtype == AD_REAL733)
  96.         ap_use_percent();
  97.  
  98.     if (ch_in -> ch_domain_norm == CH_DOMAIN_NORM_ALL)
  99.         ap_norm_all_domains();
  100.     else
  101.         ap_norm_first_domain();
  102.  
  103.     if ((mgt_inhost = qp -> inbound -> li_mta) == NULLCP) {
  104.         mgt_inhost = loc_dom_site;
  105.     } else {
  106.         char    official[LINESIZE], *subdom;
  107.  
  108.         /* normalise inbound mta */
  109.         if (tb_getdomain (mgt_inhost, NULLCP, official, 
  110.                   ch_in -> ch_ad_order,
  111.                   &subdom) == OK 
  112.             && official[0]) {
  113.             free(qp->inbound->li_mta);
  114.             mgt_inhost = qp->inbound->li_mta = strdup(official);
  115.         }
  116.         if (subdom != NULLCP) free (subdom);
  117.     }
  118.             
  119.     mgt_adtype = ch_in -> ch_in_ad_type;
  120.  
  121.     if (mgt_adtype == AD_822_TYPE) {
  122.                 qp -> content_return_request = TRUE;
  123.         /* to cope with possible 1148 conversion */
  124.         qp -> alternate_recip_allowed = TRUE;
  125.     }
  126.  
  127.     PP_TRACE (("submit/cntrl_mgt (type='%d', order='%d')",
  128.            mgt_adtype, ch_in -> ch_ad_order));
  129.  
  130.     return (RP_OK);
  131. }
  132.  
  133.  
  134.  
  135. static void hdr_eit_swap (eits, hdrs)
  136. LIST_BPT    *eits;
  137. LIST_BPT    *hdrs;
  138. {
  139.     LIST_BPT    *eits_ix, *hdrs_ix;
  140.     int        cont;
  141.  
  142.     for (eits_ix = eits; 
  143.          eits_ix != NULLIST_BPT;
  144.          eits_ix = eits_ix -> li_next) {
  145.         cont = TRUE;
  146.         for (hdrs_ix = hdrs;
  147.              hdrs_ix != NULLIST_BPT && cont == TRUE;
  148.              hdrs_ix = hdrs_ix -> li_next) {
  149.             if (lexnequ(eits_ix->li_name,
  150.                     hdrs_ix->li_name,
  151.                     strlen(eits_ix->li_name)) == 0
  152.                 && (int) strlen(eits_ix->li_name) < (int) strlen(hdrs_ix->li_name)) {
  153.                 /* prefix and swap */
  154.                 free (eits_ix->li_name);
  155.                 eits_ix->li_name = strdup(hdrs_ix->li_name);
  156.                 cont = FALSE;
  157.             }
  158.         }
  159.     }
  160. }
  161.     
  162.  
  163. int q_mgt (qp)
  164. register Q_struct       *qp;
  165. {
  166.     PP_TRACE (("submit/q_mgt (qp)"));
  167.  
  168.     /* -- generate a submit-event-id -- */
  169.     if (mgt_adtype == AD_822_TYPE ||
  170.         qp -> msgid.mpduid_string == NULLCP)
  171.         MPDUid_new (&qp -> msgid);
  172.  
  173.     /* -- add trace info -- */
  174.     trace_add (&qp -> trace, trace_new());
  175.  
  176.     if (qp -> retinterval == 0) {
  177.         switch (qp -> priority) {
  178.             case PRIO_URGENT:
  179.             qp -> retinterval = return_interval_high;
  180.             break;
  181.             case PRIO_NONURGENT:
  182.             qp -> retinterval = return_interval_low;
  183.             break;
  184.             default:
  185.             qp -> retinterval = return_interval_norm;
  186.             break;
  187.         }
  188.     }
  189.     if (qp -> warninterval == 0)
  190.         qp -> warninterval = warn_interval;
  191.  
  192.     /* -- override hdr eits that lexnequ to those specified 
  193.        in inbound channel */
  194.     hdr_eit_swap(qp->encodedinfo.eit_types, 
  195.              qp->inbound->li_chan->ch_hdr_in);
  196.     return (RP_OK);
  197. }
  198.  
  199.  
  200.  
  201.  
  202. void time_mgt(qp)
  203. Q_struct *qp;
  204. {
  205.     time_t    then, now;
  206.     char    buf[BUFSIZ];
  207.  
  208.     if (qp -> latest_time != NULLUTC) {
  209.         then = utc2time_t(qp -> latest_time);
  210.         (void) time(&now);
  211.         if (then < now) {
  212.             (void) sprintf (buf,
  213.                     "This message's latest time has been exceeded");
  214.             message_failure (DRR_UNABLE_TO_TRANSFER,
  215.                      DRD_MAX_TIME_EXPIRED,
  216.                      buf);
  217.         }
  218.     }
  219. }
  220.  
  221.  
  222.  
  223.  
  224. void msg_mgt()
  225. {
  226.     PP_TRACE (("submit/msg_mgt()"));
  227.     ch_inbound = NULLCHAN;
  228.     mgt_inhost = NULLCP;
  229. }
  230.  
  231.  
  232.  
  233.  
  234. void txt_mgt(qp)   /* -- management tasks on the input text -- */
  235. Q_struct *qp;
  236. {
  237.     PP_TRACE (("submit/txt_mgt()"));
  238.  
  239.  
  240.     /* -- if its an 822 body, check it's parts -- */
  241.     if (qp -> msgtype == MT_UMPDU &&
  242.         list_bpt_nfind (qp -> encodedinfo.eit_types,
  243.                 hdr_822_bp,
  244.                 strlen(hdr_822_bp)) != NULLIST_BPT) {
  245.         if (isnull (*io_fpart))
  246.             err_abrt (RP_MECH, "Help - lost io_part");
  247.         rd_rfchdr (io_fpart);
  248.     }
  249.     if (qp -> encodedinfo.eit_types == NULLIST_BPT) {
  250.         qp -> encodedinfo.eit_types =
  251.             list_bpt_dup (qp -> orig_encodedinfo.eit_types);
  252.         hdr_eit_swap(qp->encodedinfo.eit_types,
  253.                  qp->inbound->li_chan->ch_hdr_in);
  254.     }
  255.     /* -- check for trace looping -- */
  256.     tracecheck_mgt(qp);
  257.     /* -- currently ok -- */
  258.     pro_reply (RP_OK, "text input successful");
  259. }
  260.  
  261.  
  262.  
  263.  
  264. void message_failure (reason, diag, str)
  265. int    reason, diag;
  266. char    *str;
  267. {
  268.     ADDR    *ap, *apf = NULLADDR;
  269.     extern ADDR *ad_recip;
  270.  
  271.     for (ap = ad_recip; ap; ap = ap -> ad_next) {
  272.         if (ap -> ad_resp == FALSE)
  273.             continue;
  274.         if (ap -> ad_status != AD_STAT_PEND)
  275.             continue;
  276.         if (apf == NULLADDR)
  277.             apf = ap;
  278.         ap -> ad_status = AD_STAT_DRREQUIRED;
  279.     }
  280.     if (apf) {
  281.         apf -> ad_reason = reason;
  282.         apf -> ad_diagnostic = diag;
  283.         apf -> ad_add_info = strdup (str);
  284.     }
  285. }
  286.  
  287.  
  288.  
  289.  
  290.  
  291. /* ---------------------  Static  Routines  ------------------------------- */
  292.  
  293.  
  294.  
  295.  
  296. static void tracecheck_mgt (qp)
  297. Q_struct    *qp;
  298. {
  299.     register Trace    *tp;
  300.     int        nhops = 0, first = 0;
  301.     char        buf[BUFSIZ];
  302.     PP_TRACE (("submit/tracecheck_mgt (qp)"));
  303.  
  304.     for (tp = qp -> trace; tp != NULL; tp = tp -> trace_next) {
  305.         /* -- too many hops -- */
  306.         
  307.         if (++nhops > max_hops) {
  308.             (void) sprintf (buf,
  309.                 "%s%s %d",
  310.                 "This Message has travelled a long time, ",
  311.                 "there are too many Trace hops", nhops);
  312.             message_failure (DRR_UNABLE_TO_TRANSFER,
  313.                      DRD_LOOP_DETECTED, buf);
  314.             PP_LOG(LLOG_EXCEPTIONS,
  315.                    ("%s", buf));
  316.             return;
  317.         }
  318.  
  319.         if (tp -> trace_mta != NULLCP) {
  320.             /* can only check against those with mta specified */
  321.             if (lexequ(tp -> trace_mta, loc_dom_mta) == 0) {
  322.                 if (first >= max_loops) {
  323.                     (void) sprintf (buf, "%s%s",
  324.                             "A loop has been detected in the Trace at ",
  325.                         "field for this Message");
  326.                     PP_LOG(LLOG_EXCEPTIONS,
  327.                            ("tracecheck_mgt(%s)", buf));
  328.                     message_failure (DRR_UNABLE_TO_TRANSFER,
  329.                              DRD_LOOP_DETECTED, buf);
  330.                     return;
  331.                 } else
  332.                     first++;
  333.             }
  334.         }
  335.     }
  336. }
  337.